<?php
 $soldprovider = $soldprodmodel->search();
$soldtotals = $soldprodmodel->getTotals($soldprovider);

$buyprovider = $gotprodmodel->search();
$buytotals = $gotprodmodel->getTotals($buyprovider);

$incomesprovider = $otherincomes->search();
$incomestotals = $otherincomes->getTotals($incomesprovider);

$outcomesprovider = $otheroutcomes->search();
$outcomestotals = $otheroutcomes->getTotals($outcomesprovider);

$billssprovider = $billsoutcomes->search();
$billstotals = $billsoutcomes->getTotals($billssprovider);

$ordersprovider = $orderincomes->search();
$orderstotals = $orderincomes->getTotals($ordersprovider);

$retordersprovider = $orderret->search();
$retorderstotals = $orderret->getTotals($retordersprovider);
?>
<table class="sumtable">
<tr>
	<th>В касу</th>
	<th>Із каси</th>
</tr>
<tr>
	<td>
		<table>
			<tr>
				<td><?php echo CHtml::link("Проданий товар","#soldlink") ?></td><td><?php echo $soldtotals['sumsold'] ?></td>
			</tr>
			<tr>
				<td><?php echo CHtml::link("Інші надходження","#incomeslink") ?></td><td><?php echo $incomestotals['sumincomes'] ?></td>
			</tr>
			<tr>
				<td><?php echo CHtml::link("Замовлення","#orderslink") ?></td><td><?php echo $orderstotals['sum'] ?></td>
			</tr>
			<tr>
				<td><b>Сума</b></td><td><?php $sumincome = $soldtotals['sumsold'] + $incomestotals['sumincomes'] + $orderstotals['sum']; echo $sumincome; ?></td>
			</tr>
		</table>
	</td>
	<td>
		<table>
			<tr>
				<td><?php echo CHtml::link("Проплати накладних","#billslink") ?></td><td><?php echo $billstotals['sum'] ?></td>
			</tr>
			<tr>
				<td><?php echo CHtml::link("Інші проплати","#outcomeslink") ?></td><td><?php echo $outcomestotals['sumoutcomes'] ?></td>
			</tr>
			<tr>
				<td><?php echo CHtml::link("Повернені замовлення","#retorderslink") ?></td><td><?php echo $retorderstotals['sum'] ?></td>
			</tr>
			<tr>
				<td><b>Сума</b></td><td><?php $sumoutcome = $billstotals['sum'] + $outcomestotals['sumoutcomes'] + $retorderstotals['sum']; echo $sumoutcome; ?></td>
			</tr>
		</table>
	</td>
</tr>
</table>
<p>
<?php echo "Різниця: ".($sumincome - $sumoutcome); ?>
</p>
<fieldset id="currentdatefieldset">
<legend>Поточна дата</legend>
<?php
$this->widget('zii.widgets.jui.CJuiDatePicker', array(
    'name'=>'publishDate',
    // additional javascript options for the date picker plugin
    'options'=>"js:{onSelect:function(dateText,inst){var ajaxUrl = '/index.php?r=site/session&key=currentdate&value='+dateText;jQuery.ajax({'url':ajaxUrl,'cache':false});},'showAnim':'fold','dateFormat':'yy-mm-dd'}",
    'htmlOptions'=>array(
        'style'=>'height:20px;',
		'id'=>'publishDate',
		'class'=>'controlsblock'
    ),
	'value'=>$currentdate
));
?>
</fieldset>
<?php
echo CHtml::script('
function preparedel(id,name){
	document.getElementById("delproductid").value = id;
	document.getElementById("delproductname").innerHTML = name;
	$("#delproddialog").dialog("open"); 
	return false;
}
function preparedelbill(id,name){
	document.getElementById("delbillproductid").value = id;
	document.getElementById("delbillproductname").innerHTML = name;
	$("#delbillproddialog").dialog("open"); 
	return false;
}
');

$this->beginWidget('zii.widgets.jui.CJuiDialog', array(
    'id'=>'delproddialog',
    // additional javascript options for the dialog plugin
    'options'=>array(
        'title'=>'Повернути продукт',
        'autoOpen'=>false,
		'width'=>600
    ),
));

echo CHtml::beginForm();
?>
<table>
	<tr><td>Product:</td><td id="delproductname"></td></tr>
	<tr><td>Count:</td><td><?php echo CHtml::textField("delcount",1,array("id"=>"delcount")); ?></td></tr>
</table>
<?php
echo CHtml::hiddenField("delproductid",0,array("id"=>"delproductid"));
echo CHtml::ajaxSubmitButton('Delete',CHtml::normalizeUrl(array('store/unsold',"ajax"=>1)),array('success'=>'js: function(data) 
	{
		$("#delproddialog").dialog("close");
		$.fn.yiiGridView.update("yw0");		
	}'),array('id'=>'delproductbutton','name'=>'delproductbutton'));
echo CHtml::button('Close',array('onclick'=>'$(\'#delproddialog\').dialog("close")'));
echo CHtml::endForm();
$this->endWidget('zii.widgets.jui.CJuiDialog');

$this->beginWidget('zii.widgets.jui.CJuiDialog', array(
    'id'=>'delbillproddialog',
    // additional javascript options for the dialog plugin
    'options'=>array(
        'title'=>'Видалити продукт',
        'autoOpen'=>false,
		'width'=>600
    ),
));

echo CHtml::beginForm();
?>
<table>
	<tr><td>Product:</td><td id="delbillproductname"></td></tr>
	<tr><td>Count:</td><td><?php echo CHtml::textField("delcount",1,array("id"=>"delbillcount")); ?></td></tr>
</table>
<?php
echo CHtml::hiddenField("delproductid",0,array("id"=>"delbillproductid"));
echo CHtml::ajaxSubmitButton('Delete',CHtml::normalizeUrl(array('store/delete',"ajax"=>1)),array('success'=>'js: function(data) 
	{
		$("#delbillproddialog").dialog("close");
		$.fn.yiiGridView.update("yw1");		
	}'),array('id'=>'delproductbillbutton','name'=>'delproductbillbutton'));
echo CHtml::button('Close',array('onclick'=>'$(\'#delbillproddialog\').dialog("close")'));
echo CHtml::endForm();
$this->endWidget('zii.widgets.jui.CJuiDialog');

echo CHtml::link("","",array("name"=>"soldlink"))
?>
<fieldset id="statsoldfieldset">
<legend>Продані товари</legend>
<?php
?>
<?php
echo "Кількість: {$soldtotals['sumsoldcnt']} на суму {$soldtotals['sumsold']}";
$this->widget('zii.widgets.grid.CGridView', array(
	'dataProvider'=>$soldprovider,
	'enablePagination'=>false,
	'columns'=>array(
		array(
			'value'=>'$data->product->name',
			'header'=>'Продукт',
			'name'=>'name'
		),
		array(
			'value'=>'$data->pricesell',
			'header'=>'Ціна',
			'name'=>'price'
		),
		array(
			'value'=>'CHtml::link(CHtml::image("images/minus16x16.png"),array("#"),array("onclick"=>"currentProductId=$data->productid;preparedel($data->productid,\"".addslashes($data->product->name)."\");\$(\"#delproddialog\").dialog(\"open\");return false;"))',
			'type'=>'raw'
		),
	),
)); 
?>
</fieldset>
<?php echo CHtml::link("","",array("name"=>"boughtlink")); ?>
<fieldset id="statboughtfieldset">
<legend>Куплені товари</legend>
<?php
echo "<span style='color:white;'>Кількість: {$buytotals['sumboughtcnt']} на суму {$buytotals['sumbought']}</span>";
$this->widget('zii.widgets.grid.CGridView', array(
	'dataProvider'=>$buyprovider,
	'enablePagination'=>false,
	'columns'=>array(
		array(
			'value'=>'$data->product->name',
			'header'=>'Продукт',
			'name'=>'productname'
		),
		array(
			'value'=>'$data->pricebuy',
			'header'=>'Ціна',
			'name'=>'price'
		),
		array(
			'value'=>'$data->bill->name',
			'header'=>'Накладна',
			'name'=>'billid'
		),
		array(
			'value'=>'CHtml::link(CHtml::image("images/minus16x16.png"),array("#"),array("onclick"=>"currentProductId=$data->productid;preparedelbill($data->productid,\"".addslashes($data->product->name)."\");\$(\"#delbillproddialog\").dialog(\"open\");return false;"))',
			'type'=>'raw'
		),
	),
)); 
?>
</fieldset>
<?php echo CHtml::link("","",array("name"=>"incomeslink")); ?>
<fieldset id="statincomesfieldset">
<legend>Доход</legend>
<?php
echo "<span style='color:white;'>Кількість: {$incomestotals['sumincomescnt']} на суму {$incomestotals['sumincomes']}</span>";
$this->widget('zii.widgets.grid.CGridView', array(
	'dataProvider'=>$otherincomes->search(),
	'enablePagination'=>false,
	'columns'=>array(
		array(
			'value'=>'$data->oincome->name',
			'header'=>'Назва',
			'name'=>'incomename'
		),
		array(
			'value'=>'$data->sum',
			'header'=>'Cума',
			'name'=>'sum'
		),
		array(
			'value'=>'CHtml::link(CHtml::image("images/minus16x16.png"),CHtml::normalizeUrl(array("otherincomes/delete","id"=>$data->id,"returnUrl"=>Yii::app()->getRequest()->getUrl())))',
			'type'=>'raw'
		),

	),
)); 
?>
</fieldset>
<?php echo CHtml::link("","",array("name"=>"outcomeslink")); ?>
<fieldset id="statoutcomesfieldset">
<legend>Виплати</legend>
<?php
echo "<span style='color:black;'>Кількість: {$outcomestotals['sumoutcomescnt']} на суму {$outcomestotals['sumoutcomes']}</span>";
$this->widget('zii.widgets.grid.CGridView', array(
	'dataProvider'=>$otheroutcomes->search(),
	'enablePagination'=>false,
	'columns'=>array(
		array(
			'value'=>'$data->ooutcome->name',
			'header'=>'Назва',
			'name'=>'incomename'
		),
		array(
			'value'=>'$data->sum',
			'header'=>'Cума',
			'name'=>'sum'
		),
		array(
			'value'=>'CHtml::link(CHtml::image("images/minus16x16.png"),CHtml::normalizeUrl(array("otheroutcomes/delete","id"=>$data->id,"returnUrl"=>Yii::app()->getRequest()->getUrl())))',
			'type'=>'raw'
		),

	),
)); 
?>
</fieldset>
<?php echo CHtml::link("","",array("name"=>"billslink")); ?>
<fieldset id="currentbillfieldset">
<legend>Проплати накладних</legend>
<?php

echo "<span style='color:black;'>Кількість: {$billstotals['sumcnt']} на суму {$billstotals['sum']}</span>";

$this->widget('zii.widgets.grid.CGridView', array(
	'dataProvider'=>$billsoutcomes->search(),
	'enablePagination'=>false,
	'columns'=>array(
		array(
			'value'=>'$data->bill->name',
			'header'=>'Накладна',
			'name'=>'incomename'
		),
		array(
			'value'=>'$data->sum',
			'header'=>'Cума',
			'name'=>'sum'
		),
		array(
			'value'=>'CHtml::link(CHtml::image("images/minus16x16.png"),CHtml::normalizeUrl(array("billsoutcome/delete","id"=>$data->id,"returnUrl"=>Yii::app()->getRequest()->getUrl())))',
			'type'=>'raw'
		),

	),
)); 
?>
</fieldset>
<?php echo CHtml::link("","",array("name"=>"orderslink")); ?>
<fieldset id="currentorderfieldset">
<legend>Проплачені замовлення</legend>
<?php

echo "<span style='color:black;'>Кількість: {$orderstotals['sumcnt']} на суму {$orderstotals['sum']}</span>";

$this->widget('zii.widgets.grid.CGridView', array(
	'dataProvider'=>$orderincomes->search(),
	'enablePagination'=>false,
	'columns'=>array(
		array(
			'value'=>'(!empty($data->order->name))?$data->order->name:"Без назви"',
			'header'=>'Замовлення',
			'name'=>'incomename'
		),
		array(
			'value'=>'$data->sum',
			'header'=>'Cума',
			'name'=>'sum'
		),
		array(
			'value'=>'CHtml::link(CHtml::image("images/minus16x16.png"),CHtml::normalizeUrl(array("ordersincome/delete","id"=>$data->id,"returnUrl"=>Yii::app()->getRequest()->getUrl())))',
			'type'=>'raw'
		),

	),
)); 
?>
</fieldset>
<?php echo CHtml::link("","",array("name"=>"retorderslink")); ?>
<fieldset id="currenrettorderfieldset">
<legend>Повернені замовлення</legend>
<?php

echo "<span style='color:black;'>Кількість: {$retorderstotals['sumcnt']} на суму {$retorderstotals['sum']}</span>";
$this->widget('zii.widgets.grid.CGridView', array(
	'dataProvider'=>$orderret->search(),
	'enablePagination'=>false,
	'columns'=>array(
		array(
			'value'=>'(!empty($data->order->name))?$data->order->name:"Без назви"',
			'header'=>'Замовлення',
			'name'=>'incomename'
		),
		array(
			'value'=>'$data->sum',
			'header'=>'Cума',
			'name'=>'sum'
		),
		array(
			'value'=>'CHtml::link(CHtml::image("images/minus16x16.png"),CHtml::normalizeUrl(array("ordersincome/delete","id"=>$data->id,"returnUrl"=>Yii::app()->getRequest()->getUrl())))',
			'type'=>'raw'
		),

	),
)); 
?>
</fieldset>
